package asteroids.model.expressions;

import java.util.*;

import asteroids.model.*;

/**
 * A subclass of expression (E) that represents all the composed expressions
 * 
 * A composed expression is an expression that cantains other expressions who may or may not also contains other expressions
 * 
 * @version 1.0
 * 
 * @author	Thijs Peirelinck & Wouter Parys
 *
 */
public abstract class ComposedExpression extends E {

	@Override
	public abstract Object getValue();
	
	@Override
	public abstract boolean isValidExpression();

	@Override
	
	public abstract String getReturnType();
	
	@Override
	public abstract String toString();
	
	public abstract void validate(HashMap<String, E> variables);
	
	
	protected E getValidatedOperand(HashMap<String, E> variables, E operand) {
		if(variables.get(((Variable)operand).getValue()).getReturnType().equals("double")) {
			return new DoubleLiteral(((Double)variables.get(((Variable)operand).getValue()).getValue()));
		}
		if(variables.get(((Variable)operand).getValue()).getReturnType().equals("boolean")) {
			return new BooleanLiteral(((Boolean)variables.get(((Variable)operand).getValue()).getValue()));
		}
		else {
			assert (variables.get(((Variable)operand).getValue()).getReturnType().equals("entity")); 
			return new EntityLiteral(((FlyingObject)variables.get(((Variable)operand).getValue()).getValue()));
		}
	}
	
	@Override
	public abstract void setExecuter(Ship executer);
	

}
